﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SaleLookup.ascx.cs" Inherits="WebUI.Controls.SaleLookup" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<script type="text/javascript">
    var IMEILength = <%= WebUI.BasePage.SysVars.IMEILength %>;
    
    function txtIMEI_onchange(txt) {
        if(!isNumeric(txt.value)){
            alert("Invalid IMEI number!");
            txt.value = "";
            return;
        }
        
        if(txt.value.length >= IMEILength){
            document.getElementById("<%=btnAddIMEI.ClientID %>").click();
            txt.value='';
        }
    }       
    
    function isNumeric(value) {
        if (value != null && !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
            return true;
    }
    
    function onQtyLostFocus(txt){        
        var qty = txt.value;
        if (qty == '') qty = 1;
        if(qty == '0')
        {
            alert("Quantity = 0 is not allowed!");
            qty = 1;
            
        }
        
        txt.value = qty;
    }

    function focusOnQuantity(){
        var txt = document.getElementById('<%= txtQuantity.ClientID %>');
        txt.focus();
    }

    function focusIMEI(){
        document.getElementById('<%= txtIMEI.ClientID %>').focus();
    }
</script>

<asp:Panel ID="mainPanel" runat="server">
    <table width="100%">
        <tr>
            <td style="text-align:left; vertical-align:top;" colspan="2">
                <asp:Panel ID="imeiPanel" runat="server" GroupingText="IMEI" DefaultButton="btnAddIMEI" onfocus="this.select();"  Visible="false">
                    <asp:TextBox ID="txtIMEI"  onfocus='this.select();' runat="server" Width="98%"></asp:TextBox><br />
                    <asp:Label class="labelNote" Text="(*) Scan and press Enter." runat="server" ID="label6"></asp:Label>
                    <asp:Button ID="btnAddIMEI" runat="server" OnClick="btnAddIMEI_OnClick" style="display:none" />
                </asp:Panel>
            </td>
        </tr>
        <tr>
            <td style="text-align:left; vertical-align:top;" colspan="2">
                <asp:Label CssClass="labelMessage" ID="label1" runat="server" Text=" Or " Visible="false"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Panel ID="Panel1" runat="server" >
                    <table width="100%">
                        <tr>
                            <td style="text-align:right; vertical-align:top;">
                                <asp:Label CssClass="labelMessage" ID="label7" runat="server" Text="Bar Code:"></asp:Label>
                            </td>
                            <td style="text-align:left; vertical-align:top;">
                                <asp:Panel ID="panelBarCode" runat="server" DefaultButton="btnBarCode" >
                                    <asp:TextBox Width="200px" ID="txtBarCode" runat="server" ></asp:TextBox><br/>
                                    <asp:Label class="labelNote" Text="(*) Scan and press Enter." runat="server" ID="label8"></asp:Label>
                                    <asp:Button ID="btnBarCode" runat="server" OnClick="btnBarCode_OnClick" style="display:none" />
                                </asp:Panel>
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align:right; vertical-align:top;">
                                <asp:Label CssClass="labelMessage" ID="label3" runat="server" Text="Category:"></asp:Label>
                            </td>
                            <td style="text-align:left; vertical-align:top; ">
                                <asp:DropDownList Width="200px" ID="ddlCategory" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCategory_OnSelectedIndexChanged"></asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align:right; vertical-align:top;">
                                <asp:Label CssClass="labelMessage" ID="label4" runat="server" Text="Brand:"></asp:Label>
                            </td>
                            <td style="text-align:left; vertical-align:top;">
                                <asp:DropDownList Width="100px" ID="ddlBrand" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlBrand_OnSelectedIndexChanged"></asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align:right; vertical-align:top;">
                                <asp:Label CssClass="labelMessage" ID="label2" runat="server" Text="Product:"></asp:Label>
                            </td>
                            <td style="text-align:left; vertical-align:top;">
                                <asp:DropDownList Width="200px" ID="ddlProduct" runat="server" AutoPostBack="true" ValidationGroup="Add" OnSelectedIndexChanged="ddlProduct_OnSelectedIndexChanged"></asp:DropDownList>
                                <asp:RequiredFieldValidator class='requiredField' Display="Dynamic" ID="RequiredFieldValidator1" runat="server" ErrorMessage="required" Text="required" ValidationGroup="Add" ControlToValidate="ddlProduct"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                         <tr>
                            <td style="text-align:right; vertical-align:top;">
                                <asp:Label CssClass="labelMessage" ID="label5" runat="server" Text="Quantity:"></asp:Label>
                            </td>
                            <td style="text-align:left; vertical-align:top;">
                                <asp:TextBox Width="100px" ID="txtQuantity" runat="server" onblur='onQtyLostFocus(this);'></asp:TextBox>
                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" TargetControlID="txtQuantity"  FilterType="Numbers" runat="server">
                                </cc1:FilteredTextBoxExtender>
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align:right; vertical-align:top;">
                                
                            </td>
                            <td style="text-align:left; vertical-align:top;">
                                <asp:Button ValidationGroup="Add" ID="btnAdd" runat="server" Text="Add to Sale" OnClick="btnAdd_OnClick"></asp:Button>
                            </td>
                        </tr>
                    </table>
                </asp:Panel>
            </td>
        </tr>
    </table>
</asp:Panel>